<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="signupForm" th:object="${manufacturer}">
                        <input type="hidden" th:value="${manufacturer.id}" name="id"/>
                        <input name="orgId"  type="hidden" th:value="${manufacturer.orgId}" id="treeId"/>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">所属机构：</label>
                            <div class="col-sm-8">
                                <input class="form-control" th:value="${manufacturer.orgName}" type="text" name="orgName" onclick="selectDeptTree()" readonly="true" id="orgName">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span class="mustInput">*</span>厂商名称：</label>
                            <div class="col-sm-8">
                                <input id="name" name="name" th:value="${manufacturer.name}" data-null="请输入厂商名称" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span class="mustInput">*</span>厂商地址：</label>
                            <div class="col-sm-8">
                                <input id="address" th:value="${manufacturer.address}" name="address" data-null="请输入厂商地址" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">联系人：</label>
                            <div class="col-sm-8">
                                <input id="contact" th:value="${manufacturer.contact}" name="contact"class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">联系电话：</label>
                            <div class="col-sm-8">
                                <input id="phone" th:value="${manufacturer.phone}" name="phone"class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">网址：</label>
                            <div class="col-sm-8">
                                <input id="website" th:value="${manufacturer.website}" name="website" class="form-control" type="text">
                            </div>
                        </div>
                        <!-- 附加信息结束 -->
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <div class="btn btn-primary" onclick="save()">提交</div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<div th:include="include::footer"></div>
<script>

    function save() {
        // 必输校验
        var hasFlag = 0;
        $('#signupForm input').each(function (index, item) {
            var val = $.trim($(item).val());
            var dataNull = $(item).data('null');
            if (!val && !hasFlag && dataNull) {
                hasFlag = 1;
                layer.msg(dataNull);
            }
        })
        if (hasFlag) {
            return;
        }
        $.ajax({
            cache: true,
            type: "POST",
            url:  ctx+"cdzManufacturer/editSave",
            data: $('#signupForm').serialize(), // 你的formid
            async: false,
            error: function (request) {
                parent.layer.alert("网络超时");
            },
            success: function (data) {
                if (data.code == 0) {
                    parent.layer.msg("操作成功");
                    parent.reLoad();
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                } else {
                    parent.layer.alert(data.msg)
                }

            }
        });
    }


    function selectDeptTree() {
        var treeId = $("#treeId").val();
        var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
        var url = ctx + "system/dept/selectDeptTree/" + deptId;
        var options = {
            title: '选择部门',
            width: "380",
            url: ctx + "system/dept/selectDeptTree/" + deptId,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero){
        var body = layer.getChildFrame('body', index);
        $("#treeId").val(body.find('#treeId').val());
        $("#orgName").val(body.find('#treeName').val());
        layer.close(index);
    }

</script>
</body>
</html>